package com.axjy.controller;


import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.axjy.pojo.Manager;
import com.axjy.pojo.QuanXian;
import com.axjy.pojo.QuanXianFeiLei;
import com.axjy.service.ManagerService;
import com.axjy.service.QuanXianService;

@Controller
public class LoginController {
	
	@Resource
	private ManagerService managerService;
	
	@Resource
	private QuanXianService quanXianService;
	
	
	@RequestMapping(value="/login",method=RequestMethod.GET)
	public String login() {
		return "login";
	}
	
	@RequestMapping(value="/system/manager",method=RequestMethod.GET)
	public String sys_manage() {
		return "system/manager";
	}	
	
	
	
	
	
	@RequestMapping(value="/login",method=RequestMethod.POST)
	public String login(String mgName, String mgPWD,Model model,HttpSession session) {
		Manager manager=managerService.getManager(mgName, mgPWD);
		if(manager==null) {
			model.addAttribute("errors", "用户名或密码错误");
			return "/login";
		}
		List<Integer> list = quanXianService.get(manager);
		/*System.out.println("拿到的数字集合"+list.toString());*/
		TreeMap<QuanXianFeiLei, List<QuanXian>> map = quanXianService.getQuanXian(manager,list);
		manager.setQuanxian(map);
		session.setAttribute("manager", manager);
		return "redirect:/main";
		
	}
}
